Force usage of common gbfile api.
authoroliskoli <oliskoli>
Wed, 30 Aug 2006 20:34:20 +0000 (20:34 +0000)
committeroliskoli <oliskoli>
Wed, 30 Aug 2006 20:34:20 +0000 (20:34 +0000)
'textfile' is now part of the history of GPSBabel.

csv_util.c
csv_util.h
xcsv.c

index fdb14b7e94e1e04163d1bb289f77d4272dfe17bf..3b0b907ea025dbd84f03805b98cbb6d544b21b9f 100644 (file)
@@ -1001,11 +1001,8 @@ xcsv_data_read(void)
     queue *elem, *tmp;
     field_map_t *fmp;
     ogue_t *ogp;
-    textfile_t *tin;
     
-    tin = textfile_init(xcsv_file.xcsvfp);
-
-    while ((buff = textfile_read(tin))) {
+    while ((buff = gbfgetstr(xcsv_file.xcsvfp))) {
         linecount++;
         buff = lrtrim(buff);
 
@@ -1061,7 +1058,6 @@ xcsv_data_read(void)
         }
 
     }
-    textfile_done(tin);
 }
 
 static void
@@ -1150,7 +1146,7 @@ xcsv_waypt_pr(const waypoint *wpt)
         fmp = (field_map_t *) elem;
 
         if ((i != 0) && !(fmp->options & OPTIONS_NODELIM))  
-            fprintf (xcsv_file.xcsvfp, write_delimiter);
+            gbfprintf (xcsv_file.xcsvfp, write_delimiter);
 
        if (fmp->options & OPTIONS_ABSOLUTE) {
                lat = fabs(lat);
@@ -1454,16 +1450,16 @@ xcsv_waypt_pr(const waypoint *wpt)
         * ""%s"" to smuggle bad characters through.
         */
        if (0 == strcmp(fmp->printfc, "\"%s\"")) {
-               fprintf (xcsv_file.xcsvfp, "\"%s\"", obuff);
+               gbfprintf (xcsv_file.xcsvfp, "\"%s\"", obuff);
        } else {
-               fprintf (xcsv_file.xcsvfp, "%s", obuff);
+               gbfprintf (xcsv_file.xcsvfp, "%s", obuff);
        }
 
 next:
        xfree(obuff);
     }
 
-    fprintf (xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
+    gbfprintf (xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
 
     if (description && description != shortname)
         xfree(description);
@@ -1502,12 +1498,12 @@ xcsv_data_write(void)
        ol = strsub(ogp->val, "__FILE__", xcsv_file.fname);
 
        if (ol) {
-               fprintf(xcsv_file.xcsvfp, "%s", ol);
+               gbfprintf(xcsv_file.xcsvfp, "%s", ol);
                xfree(ol);
        } else {
-               fprintf(xcsv_file.xcsvfp, "%s", ogp->val);
+               gbfprintf(xcsv_file.xcsvfp, "%s", ogp->val);
        }
-       fprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
+       gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
     }
 
     waypt_disp_all(xcsv_waypt_pr);
@@ -1517,7 +1513,7 @@ xcsv_data_write(void)
     /* output epilogue lines, if any. */
     QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
         ogp = (ogue_t *) elem;
-        fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
+        gbfprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
     }
 }
 #endif
index c93cc6e9bc305601e51a15d187c91ec939e07aaf..8da2d3e2a89896a91885aea27d40d37a45d6a2df 100644 (file)
@@ -123,7 +123,7 @@ typedef struct {
     int ifield_ct;             /* actual # of ifields */
     int ofield_ct;             /* actual # of ofields */
     
-    FILE * xcsvfp;             /* ptr to current *open* data file */
+    gbfile * xcsvfp;           /* ptr to current *open* data file */
     char * fname;                /* ptr to filename of above. */
 
     char * description;                /* Description for help text */
diff --git a/xcsv.c b/xcsv.c
index 64a4ff34eaeafd1b9a75fcc65d8832de1b5ebf09..32837cd8b0077fc922cd0c31919ea0b268ad6e4f 100644 (file)
--- a/xcsv.c
+++ b/xcsv.c
@@ -441,18 +441,16 @@ static void
 xcsv_read_style(const char *fname)
 {
     char *sbuff;
-    FILE *fp;
-    textfile_t *tin;
+    gbfile *fp;
 
     xcsv_file_init();
 
-    fp = xfopen(fname, "rb", MYNAME);
-    tin = textfile_init(fp);
+    fp = gbfopen(fname, "rb", MYNAME);
 
-    while ((sbuff = textfile_read(tin))) {
+    while ((sbuff = gbfgetstr(fp))) {
         sbuff = lrtrim(sbuff);
        xcsv_parse_style_line(sbuff);
-    } while (!feof(fp));
+    } while (!gbfeof(fp));
 
     /* if we have no output fields, use input fields as output fields */
     if (xcsv_file.ofield_ct == 0) {
@@ -461,8 +459,7 @@ xcsv_read_style(const char *fname)
         xcsv_file.ofield = &xcsv_file.ifield;
         xcsv_file.ofield_ct = xcsv_file.ifield_ct;
     }
-    textfile_done(tin);
-    fclose(fp);
+    gbfclose(fp);
 }
 
 /*
@@ -519,14 +516,14 @@ xcsv_rd_init(const char *fname)
        warning(MYNAME " attempt to read %s as a track or route, but this module only supports waypoints on read.  Reading as waypoints instead.\n", fname);
     }
 
-    xcsv_file.xcsvfp = xfopen(fname, "r", MYNAME);
+    xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME);
 
 }
 
 static void
 xcsv_rd_deinit(void)
 {
-    fclose(xcsv_file.xcsvfp);
+    gbfclose(xcsv_file.xcsvfp);
 
     xcsv_destroy_style();
 }
@@ -548,7 +545,7 @@ xcsv_wr_init(const char *fname)
         xcsv_read_style(styleopt);
     }
 
-    xcsv_file.xcsvfp = xfopen(fname, "w", MYNAME);
+    xcsv_file.xcsvfp = gbfopen(fname, "w", MYNAME);
     xcsv_file.fname = (char *)fname;
 
     /* set mkshort options from the command line */
@@ -575,7 +572,7 @@ xcsv_wr_init(const char *fname)
 static void
 xcsv_wr_deinit(void)
 {
-    fclose(xcsv_file.xcsvfp);
+    gbfclose(xcsv_file.xcsvfp);
 
     xcsv_destroy_style();
 }